
<!--租客管理-->
<template>
  <div class="app-container">

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:contract:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:contract:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:contract:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:contract:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="contractList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="租客姓名" align="center" prop="tenantName" />
      <el-table-column label="合同编号" align="center" prop="cfContractNo" />
      <el-table-column label="电话" align="center" prop="tenantPhone" />
      <el-table-column label="小区名" align="center" prop="premiseName" />

      <el-table-column label="房源类型" align="center" prop="signType" >
        <template scope="scope">
          {{scope.row.signType==0?"整租（分散式）":""}}
          {{scope.row.signType==1?"合租（分散式）":""}}
          {{scope.row.signType==2?"单身公寓（集中式）":""}}
        </template>
      </el-table-column>

      <el-table-column label="租约期限开始日" align="center" prop="startDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="租约期限结束日" align="center" prop="endDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="押付方式" align="center" prop="shu" />

      <el-table-column label="押金" align="center" prop="depositType" />

      <el-table-column label="租金" align="center" prop="paymentType" />

      <el-table-column label="状态" align="center" prop="contractState" >
        <template scope="scope">
          {{scope.row.contractState==2?"已提交":""}}
          {{scope.row.contractState==3?"已解约":""}}
          {{scope.row.contractState==4?"已结束":""}}
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listContract, getContract, delContract, addContract, updateContract } from "@/api/housings/contract/contract";

export default {
  name: "Contract",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      contractList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cfContractNo: null,
        outContractNo: null,
        lastContractId: null,
        lastContractNo: null,
        businessId: null,
        deptId: null,
        deptNo: null,
        roomId: null,
        roomCode: null,
        roomName: null,
        sfContractId: null,
        sfContractNo: null,
        houseId: null,
        houseName: null,
        premiseName: null,
        peopleNum: null,
        tenantId: null,
        tenantName: null,
        tenantPhone: null,
        tenantEmergencyPhone: null,
        tenantCardNo: null,
        tenantContactAddress: null,
        startDate: null,
        endDate: null,
        signingCycle: null,
        monthRent: null,
        deposit: null,
        depositType: null,
        paymentType: null,
        advanceDays: null,
        fixedDay: null,
        tenantExpenses: null,
        signType: null,
        supplementaryTerms: null,
        haveSpecialPeople: null,
        rentInstallmentFlg: null,
        zyblFlg: null,
        contractState: null,
        xuyueState: null,
        freezeStatus: null,
        inputDate: null,
        signingDate: null,
        auditDate: null,
        inputUserId: null,
        cfUserId: null,
        cfUserName: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        cfContractNo: [
          { required: true, message: "出房合同编号不能为空", trigger: "blur" }
        ],
        businessId: [
          { required: true, message: "商户ID不能为空", trigger: "blur" }
        ],
        roomId: [
          { required: true, message: "房源ID不能为空", trigger: "blur" }
        ],
        tenantId: [
          { required: true, message: "租客ID不能为空", trigger: "blur" }
        ],
        cfUserId: [
          { required: true, message: "出房人,暂定设置为创建人不能为空", trigger: "blur" }
        ],
        cfUserName: [
          { required: true, message: "出房人姓名不能为空", trigger: "blur" }
        ],
        delFlg: [
          { required: true, message: "删除标识,0:未删除，1:删除不能为空", trigger: "blur" }
        ],
        createUserid: [
          { required: true, message: "创建用户ID不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateUserid: [
          { required: true, message: "更新用户ID不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listContract(this.queryParams).then(response => {
        this.contractList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        cfContractNo: null,
        outContractNo: null,
        lastContractId: null,
        lastContractNo: null,
        businessId: null,
        deptId: null,
        deptNo: null,
        roomId: null,
        roomCode: null,
        roomName: null,
        sfContractId: null,
        sfContractNo: null,
        houseId: null,
        houseName: null,
        premiseName: null,
        peopleNum: null,
        tenantId: null,
        tenantName: null,
        tenantPhone: null,
        tenantEmergencyPhone: null,
        tenantCardNo: null,
        tenantContactAddress: null,
        startDate: null,
        endDate: null,
        signingCycle: null,
        monthRent: null,
        deposit: null,
        depositType: null,
        paymentType: null,
        advanceDays: null,
        fixedDay: null,
        tenantExpenses: null,
        signType: null,
        supplementaryTerms: null,
        haveSpecialPeople: null,
        rentInstallmentFlg: null,
        zyblFlg: null,
        contractState: null,
        xuyueState: null,
        freezeStatus: 0,
        inputDate: null,
        signingDate: null,
        auditDate: null,
        inputUserId: null,
        cfUserId: null,
        cfUserName: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getContract(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateContract(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addContract(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delContract(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/contract/export', {
        ...this.queryParams
      }, `system_contract.xlsx`)
    }
  }
};
</script>
